<script>
import { fetchList, activeArticle } from '@/api/employee'
import waves from '@/directive/waves' // waves directive水波纹特效？
import Pagination from '@/components/Pagination' // 基于el分页的二次封装

export default {
  name: 'ComplexTable',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      list: [],
      total: 0,
      listLoading: true,
      // 搜索框请求数据及分页数据
      listQuery: {
        page: 1,
        pageSize: 10,
        state: 2,
        role: '',
        query: ''
      }
    }
  },
  // 钩子函数，当界面创建的时候调用.getList() 获取列表数据
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      // 获取表格数据
      fetchList(this.listQuery).then(response => {
        if (response.resultCode === 200) {
          this.list = response.data.list
          this.total = response.data.count
          this.pageSize = response.data.limit
          this.listLoading = false
        }
      })
      if (this.listLoading) {
        setTimeout(() => {
          this.listLoading = false
        }, 2000)
      }
    },

    handleFilter() {
      this.listQuery.page = 1
      this.listQuery.pageSize = 10
      this.getList()
    },

    handleChangeState(row) {
      activeArticle(row.id).then(res => {
        if (res.resultCode === 200) {
          this.$notify({
            title: '提示',
            message: '启用成功',
            type: 'success',
            duration: 2000
          })
          this.getList()
        }
      })
    }
  }
}
</script>

<style lang="scss">
  .footer {
    background-color: #ecf5ff;
    color: black;
    margin: 0;
    position:absolute; /* 必要 */
    bottom:0; /* 必要 */
    width: 100%;
  }
</style>

<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.query" placeholder="请输入关键词" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查找成员
      </el-button>
    </div>

    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%">
      <el-table-column label="头像" prop="img" width="80" align="center">
          <template slot-scope="{row}">
            <img :src="'http://'+row.img" alt="无" width="60px" height="60px">
          </template>
      </el-table-column>
      <el-table-column label="姓名" prop="name" align="center"/>
      <el-table-column label="学号" prop="account" align="center"/>
      <el-table-column label="角色" prop="roleName" align="center"/>
      <el-table-column label="性别" prop="sexName" align="center"/>
      <el-table-column label="邮箱" prop="email" align="center"/>
      <el-table-column label="手机号" prop="phone" align="center"/>
      <el-table-column label="创建时间" prop="createTime" align="center"/>
      <el-table-column label="修改时间" prop="updateTime" align="center"/>

      <el-table-column label="操作" align="center" min-width="80" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button type="success" size="mini" @click="handleChangeState(row)">
            启用
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
  </div>
</template>

<style lang="scss">
  .footer {
    background-color: #ecf5ff;
    color: black;
    margin: 0;
    position:absolute; /* 必要 */
    bottom:0; /* 必要 */
    width: 100%;
  }
</style>

